<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>计算文件的 sha1 散列值</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.setlocale.html">setlocale</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.sha1.html">sha1</a></div>
 <div class="up"><a href="ref.strings.html">字符串函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.sha1-file" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sha1_file</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5)</p><p class="refpurpose"><span class="refname">sha1_file</span> &mdash; <span class="dc-title">计算文件的 sha1 散列值</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.sha1-file-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>sha1_file</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$raw_output</code><span class="initializer"> = false</span></span>
  ] )</div>

  <p class="simpara">
   利用<a href="http://www.faqs.org/rfcs/rfc3174" class="link external">&raquo;&nbsp;美国安全散列算法 1</a>，计算并返回由 <em><code class="parameter">filename</code></em> 指定的文件的 sha1 散列值。该散列值是一个 40 字符长度的十六进制数字。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.sha1-file-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">filename</code></em></dt>

     <dd>

      <p class="para">
       要散列的文件的文件名。
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">raw_output</code></em></dt>

     <dd>

      <p class="para">
       如果被设置为 <strong><code>TRUE</code></strong>，sha1 摘要将以 20 字符长度的原始格式返回。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.sha1-file-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功返回一个字符串，否则返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.sha1-file-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4762">
    <p><strong>Example #1 <span class="function"><strong>sha1_file()</strong></span> 范例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">foreach(</span><span style="color: #0000BB">glob</span><span style="color: #007700">(</span><span style="color: #DD0000">'/home/Kalle/myproject/*.php'</span><span style="color: #007700">)&nbsp;as&nbsp;</span><span style="color: #0000BB">$ent</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">is_dir</span><span style="color: #007700">(</span><span style="color: #0000BB">$ent</span><span style="color: #007700">))<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$ent&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">'&nbsp;(SHA1:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">sha1_file</span><span style="color: #007700">(</span><span style="color: #0000BB">$ent</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">')'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>

 <div class="refsect1 changelog" id="refsect1-function.sha1-file-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.0.0</td>
       <td>
       新增 <em><code class="parameter">raw_output</code></em> 参数。
       </td>
      </tr>

      <tr>
       <td>5.1.0</td>
       <td>
        改变函数以使用流 API。这意味着可以使用包装器，比如 <em>sha1_file(&#039;http://example.com/..&#039;)</em>。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.sha1-file-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.sha1.html" class="function" rel="rdfs-seeAlso">sha1()</a> - 计算字符串的 sha1 散列值</span></li>
    <li class="member"><span class="function"><a href="function.md5-file.html" class="function" rel="rdfs-seeAlso">md5_file()</a> - 计算指定文件的 MD5 散列值</span></li>
    <li class="member"><span class="function"><a href="function.crc32.html" class="function" rel="rdfs-seeAlso">crc32()</a> - 计算一个字符串的 crc32 多项式</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.setlocale.html">setlocale</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.sha1.html">sha1</a></div>
 <div class="up"><a href="ref.strings.html">字符串函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
